import { desktopCapturer } from 'electron'

function getScreens() {
	desktopCapturer.getSources({ types: ['window', 'screen'] }).then(
		sources => {
			const source = sources.find(item => item.name === 'QQ音乐')
			getInitStream(source)
		})
}

function getInitStream(source) {
// 获取指定窗口的媒体流
	navigator.mediaDevices.getUserMedia({
		audio: false,
		video: {
			mandatory: {
				chromeMediaSource: 'desktop',
				chromeMediaSourceId: source.id
			}
		}
	}).then(stream => {
		getSdkStream(stream)
	})
}

function getSdkStream(stream) {
	this.shareStream = TRTC.createStream({
		audioSource: stream.getAudioTracks()[0],
		videoSource: stream.getVideoTracks()[0]
	})
}
